package cn.taoticket.controller;

import cn.taoticket.common.Dto;
import cn.taoticket.common.DtoUtil;
import cn.taoticket.service.TaoTicketUserService;
import cn.taoticket.vo.QueryLinkUserVo;
import cn.taoticket.vo.TTUserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping(value = "/api")
public class LinkUserController {
    @Autowired
    private TaoTicketUserService taoTicketUserService;

    @RequestMapping(value = "/v/queryLinkUser", method = RequestMethod.POST)
    public Dto queryLinkUserByUserId(HttpServletRequest request) throws Exception {
        String user_token = request.getHeader("token");
        //根据用户token获取当前联系人的信息并且把信息封装成TaoticketUserVo对象
        TTUserVO ttUserVO = taoTicketUserService.loadCurrentUserByTokenAsTaoticketUserVo(user_token);
        //根据查询到的当前用户Id获取常用联系人
        List<QueryLinkUserVo> queryLinkUserVos = taoTicketUserService.findLinkUserByUserId(ttUserVO.getUserId());
        return DtoUtil.returnDataSuccess(queryLinkUserVos);
    }
}
